import java.lang.reflect.Array;
import java.util.Arrays;

public class Company {
    String cname;
    String adress;
    String number;
    String scope;
    double max;
    String s;
    Staff[] c = new Staff[100];
    int count = 0;

    //添加员工
    public boolean add(String newName, int newAge, char newSex, String newPost, double newSalary) {
        if (count >= c.length) {
            System.out.println("员工已招满");
            return false;
        }
        c[count] = new Staff();
        c[count].name = newName;
        c[count].age = newAge;
        c[count].sex = newSex;
        c[count].post = newPost;
        c[count].salary = newSalary;
        count++;
        return true;

    }

    //输出员工信息
    public void showStaff() {
        System.out.println("显示员工信息");
        System.out.println("序号\t姓名\t年龄\t性别\t职务\t薪水");
        for (int i = 0; i < count; i++) {
            System.out.println((i + 1) + " " + c[i].name + " " + c[i].age + " " + c[i].sex + " " + c[i].post + " " + c[i].salary);
        }
    }

    //输出公司信息
    public void showCompany() {
        System.out.println("公司名称" + cname);
        System.out.println("公司地址" + adress);
        System.out.println("公司电话号码" + number);
        System.out.println("公司经营范围" + scope);
    }

    //统计员工总人数
    public int getCount() {
        return count;
    }

    //辞退员工
    public boolean fire(String name) {
        for (int i = 0; i < count; i++) {
            if (c[i].name.equals(name)) {
                for (int j = i; j < count - 1; j++) {
                    c[j] = c[j + 1];
                }
                c[count - 1] = null;
                count--;
                System.out.println("员工已辞退");
                return true;
            }

        }
        return false;
    }

    //    查找薪水最高的员工
    public void findTopSlary() {
        max = c[0].salary;
        int j = 0;
        for (int i = 1; i < count; i++) {
            if (max < c[i].salary) {
                max = c[i].salary;
                j = i;
            }
            System.out.println("工资最高员工姓名为：" + c[i].name + "他的工资是" + c[i].salary);
        }

    }

    //从高到低排工资
    public void sortSalary() {
        for (int i = 0; i < count; i++) {
            for (int j = i; j < count - 1; j++) {
                if (c[j + 1].salary > c[j].salary) {
                    Staff temp = c[j];
                    c[j + 1] = c[j];
                    c[j] = temp;
                    System.out.println(c[j]);
                }
            }
        }

    }

    //算平均工资
    public double avgSalary() {
        double numSalary = 0;
        for (int i = 0; i < count; i++) {
            numSalary += c[i].salary;
        }
        return numSalary / count;
    }

    //给所有员工涨工资：如果员工的工资小于5000，则涨500元；否则涨100元
    public void  addSalary() {
        for (int i = 0; i < count; i++) {
            if (c[i].salary <= 5000) {
                c[i].salary += 500;
                continue;
            }
            c[i].salary += 100;
        }


    }
}



